<?php
abstract class Controller_List extends Controller {
	
	/**
	 * 在执行actionIndex之前设置index的condition数组
	 * @param &array $conditions
	 */
	protected function _setIndexCondition(&$conditions){
		
	}
	
	function actionIndex()
	{
		
		$limit = _gp('limit','int') ? _gp('limit','int') : C('PAGESIZE');
		$sort = _gp("sort","string") ? _gp("sort","string") : $this->model->getPkName();
		$dir = _gp("dir","string") ? _gp("dir","string") : "desc";

		$conditions = array();		
		$message = "";

		$this->_setIndexCondition($conditions, $message);
   		
		$this->setBack();

    	if (!empty($conditions)) {
    		$sql_where .= ' and ' . join(" and ", $conditions);
    	}

		$total = $this->selectCount("where 1 $sql_where");
		$pager = new Pagination($total, $limit, _gp('page', 'int'));
		$pager_min = $pager->minimum;
		$data = $this->select("*", "where 1 $sql_where order by `$sort` $dir limit $pager_min,$limit");
		$this->assign('pager',$pager->display);
		$this->assign('message',$message);
		$this->assign('data',$data);
		$this->assign('pk',$this->model->getPkName());

		$this->display($this->_tplForIndex);

	}
}
